package ntrees.hu.pxinput;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.Log;

public class ArcTextView extends ArcView {
	/**
	 * 弧形字串*/
	private static Paint textPain;
	private String mText;

	static {
    	textPain = new Paint(Paint.ANTI_ALIAS_FLAG);
    	textPain.setColor(Color.WHITE);
    	textPain.setTextSize(20);
    	//textPain.setStrokeWidth(3);
	}
	
	public ArcTextView(Context context) {
		super(context);
	}
	
	public ArcTextView(Context context, String text, float angle, int width, int radius) {
		super(context);
		setAngle(angle);
		setWidth(width);
		setRadius(radius);
		setText(text);
	}
	
	public ArcTextView(Context context, String text) {
		super(context);
		setText(text);
	}
	
	public void setText(int id) {
		setText(mContext.getString(id));
	}
	
	public void setText(String text) {
		mText = text;
		float length = paint.measureText(mText)*2f;
		//sweepAngle = (float) (((float)360.0f * length)/ (2.0f * Math.PI * radius()));
		//dump("setText");
	}
	
	public void onDraw(Canvas canvas) {
		//canvas.drawColor(Color.GRAY);
		if (paint == null) {
			paint = new Paint();
		}
		Path path = new Path();
		path.addArc(rect(), startAngle(), /*360*/sweepAngle());
    	canvas.drawPath(path, paint);
    	canvas.drawTextOnPath(mText, path, 0, 10, textPain);
    	//Log.d("", "---------------> startAngle: " + startAngle());
    	dump("ArcTextView, onDraw " + mText);
	}
	
	public float sweepAngle() {
		float length = paint.measureText(mText)*2f;
		return (float) (((float)360.0f * length)/ (2.0f * Math.PI * radius()));
	}
	
//	public float length() {
//		return paint.measureText(mText)*2f;
//	}
	
	public int width() {
		return 35;
	}
	
	public void setSweepAngle(float l) {
		throw new UnsupportedOperationException(getClass().getName() + " can not set length");
	}
}
